﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EIA.Basic.Model;
using System.Collections;
using EIA.Basic.DAL;

namespace EIA.Basic.BLL
{
    public class XDictBlp : IXDictBlp
    {
        IDicTypeDao _DicTypeDao = null;
        IDicItemDao _DicItemDao = null;

        public XDictBlp()
        {
            _DicTypeDao = X.DaoFactory.Create<IDicTypeDao>();
            _DicItemDao = X.DaoFactory.Create<IDicItemDao>();
        }

        public IList<DicType> ListType(int type)
        {
            Dictionary<string, object> con = new Dictionary<string, object>();
            con[DicType._TYPE] = type;
            return _DicTypeDao.List(con);
        }

        public int Insert(DicItem item)
        {
            var k = _DicItemDao.Insert(item);
            return k == null ? 0 : (int)k;
        }

        public bool Update(DicItem item)
        {
            return _DicItemDao.Update(item);
        }

        public bool Delete(DicItem item)
        {
            return _DicItemDao.Delete(item) > 0;
        }

        public int Count(string type_id)
        {
            Dictionary<string, object> con = new Dictionary<string, object>();
            con[DicItem.DIC_TID] = type_id;
            return _DicItemDao.Count(con);
        }

        public IList<DicItem> List(string type_id, int pagesize, int page)
        {
            Dictionary<string, object> con = new Dictionary<string, object>();
            con[DicItem.DIC_TID] = type_id;
            return _DicItemDao.List(con, pagesize, page);
        }

    }
}
